// 服务配置
package server

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"gqlgen-test2/logger"
	"gqlgen-test2/server/handler"
	"gqlgen-test2/server/middleware"
	"gqlgen-test2/setting"
	"log"
)

// 初始化服务配置
func Setup() {
	gin.SetMode(setting.SERVER_SETTING.GinMode)
	// 创建gin
	r := gin.New()
	// 设置Gin中间件
	r.Use(gin.RecoveryWithWriter(logger.LOG.Writer()))
	r.Use(middleware.LoggerMiddleware())
	// 设置路由
	r.POST("/query", handler.GraphqlHandler())
	r.GET("/", handler.PlaygroundHandler())

	addr := fmt.Sprintf("%s:%s", setting.SERVER_SETTING.Host, setting.SERVER_SETTING.Port)
	log.Printf("connect to  for GraphQL playground", addr)
	log.Fatal(r.Run(addr))
}
